import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class HomeBanner extends StatelessWidget {
  //接受数据
  const HomeBanner({Key? key, required this.bannerList}) : super(key: key);

  final List bannerList;
  @override
  Widget build(BuildContext context) {
    if (bannerList.isNotEmpty) {
      return CarouselSlider(
        items: bannerList
            .map((item) => GestureDetector(
                  onTap: () {
                    if (kDebugMode) {
                      print('点击轮播图');
                    }
                  },
                  child: Container(
                    margin: const EdgeInsets.all(5),
                    child: Image.network(
                      item['imgUrl'],
                      fit: BoxFit.cover,
                    ),
                  ),
                ))
            .toList(),
        //轮播图常用配置
        options: CarouselOptions(
          autoPlay: true,
          autoPlayInterval: const Duration(seconds: 2),
          height: 150,
        ),
      );
    } else {
      return Container();
    }
  }
}
